home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / pdisk.zip / SLEEP.C < prev    next >
Text File  |  1989-01-12  |  725b  |  24 lines

  1. /* sleep for a number of milliseconds -- interrupted by kbd */
  2. /* returns zero if uninterrupted, else -1 */
  3. #include <dos.h>
  4.  
  5. int
  6. sleep(ticks)        
  7. long ticks;
  8. {
  9.     union REGS kregs, cregs;
  10.     long dostime, newtime;
  11.  
  12.     kregs.h.ah = 0x0b;    /* "check keyoard status" */
  13.     cregs.h.ah = 0x2c;    /* "get time" */
  14.     ticks /= 10L;    /* clock() deals in hundreths of seconds */
  15.     intdos(&cregs,&cregs);
  16.     dostime=cregs.h.ch*360000 + cregs.h.cl*6000 + cregs.h.dh*100 + cregs.h.dl;
  17.     do {
  18.         intdos(&cregs,&cregs);
  19.         newtime=cregs.h.ch*360000+cregs.h.cl*6000+cregs.h.dh*100+cregs.h.dl;
  20.         intdos(&kregs,&kregs);            /* see if keystroke is available */
  21.     } while((newtime-dostime) < ticks && !kregs.h.al);
  22.     return((int) kregs.h.al);
  23. }
  24.